#include <QApplication>
#include <QTranslator>
#include <QCommandLineParser>

#include "common.h"
#include "dynamicmapmanagewindow.h"
#include "simulatewidget.h"

#ifdef _WIN32
#include "mainwindow.h"
#endif

#define VERSION "V1.10.4"

#ifdef __WIN32__
bool g_debug_flag = true;
bool g_run_python = false;
#else
bool g_debug_flag = false;
bool g_run_python = true;
#endif

QCommandLineOption g_debug_option(QStringList() << "d" << "debug", QCoreApplication::translate("main", "print debug log."));
QCommandLineOption g_python_option(QStringList() << "w" << "without-python", QCoreApplication::translate("main", "run dynamicMap without python mod."));

void SetCommandLineOpt(QCommandLineParser *parser)
{
    parser->setApplicationDescription(QGuiApplication::translate("main", "\nHuaQi dynamicmap software"));  // 设置应用程序描述信息
    parser->addHelpOption();     // 添加帮助选项 ("-h" 或 "--help")
    parser->addVersionOption();  // 添加版本选项 ("-v" 或 "--version")
    parser->addOption(g_debug_option);
    parser->addOption(g_python_option);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);
    a.setApplicationVersion(VERSION);

#ifdef __WIN32__

    QFile qssFile(":/style/MyStyleSheet.qss");
    qssFile.open(QFile::ReadOnly);
    if (qssFile.isOpen())
    {
        QString qss = QLatin1String(qssFile.readAll());
        qApp->setStyleSheet(qss);
        qssFile.close();
    }

    QTranslator *translator = new QTranslator();
    translator->load(":/language/langChinese.qm");
//    translator->load(":/language/langEnglish.qm");
    qApp->installTranslator(translator);

    a.setApplicationName("动态地图编辑软件" VERSION);

    QFont font = a.font();
    font.setFamily("Microsoft YaHei");
    a.setFont(font);

    MainWindow w;
    w.show();

#else

    QCommandLineParser parser;
    SetCommandLineOpt(&parser);
    parser.process(a);
    g_debug_flag = parser.isSet(g_debug_option);
    g_run_python = !parser.isSet(g_python_option);

    LOG_PRINTF("version: %s\n", VERSION);
    LOG_PRINTF("debug_flag:%d\n", g_debug_flag);
    LOG_PRINTF("run_python:%d\n", g_run_python);

    DynamicMapManageWindow w;

//    SimulateWidget w;
//    w.simulate_show_init(28, Up);
#endif

    return a.exec();
}
